<?php

//表格
class Pj
{

	public function index()
	{
		$a['pt']="腾讯";
		$content1 = Project::find_week($a);
		$a['pt']="FB繁体";
		$content2 = Project::find_week($a);
		$a['pt']="FB泰语";
		$content3 = Project::find_week($a);
		$a['pt']="Mixi";
		$content4 = Project::find_week($a);
		$a['pt']="飞信";
		$content5 = Project::find_week($a);
		

		view('project', array('title' => '工作计划', 
		     'content1' => $content1,
		     'content2' => $content2,
		     'content3' => $content3,
		     'content4' => $content4,
		     'content5' => $content5,));
	}

	public function editProject()
	{
		$arr['pid'] = $_GET['id'];
		$content = Project::find($arr);
		$a['part']=1;
		$content_user1 = User::find($a);
		$a['part']=2;
		$content_user2 = User::find($a);
		$a['part']=3;
		$content_user3 = User::find($a);
		$a['part']=4;
		$content_user4 = User::find($a);
		$a['part']=5;
		$content_user5 = User::find($a);
//		print_r($content_user1);
		view('pro_edit', array('title' => '工作计划', 
		     'content' => $content, 
		     'content_user1'=>$content_user1,
		     'content_user2'=>$content_user2,
		     'content_user3'=>$content_user3,
		     'content_user4'=>$content_user4,
		     'content_user5'=>$content_user5,));
	}

	public function edit()
	{
		$arr=$_POST;
		if($arr['fd']=="starttime")
		{
			$t=strtotime($arr['val']);
			$arr['val']=date("Y/m/d", $t);
		}
		if($arr['fd']=="endtime")
		{
			$t=strtotime($arr['val']);
			$arr['val']=date("Y/m/d", $t);
		}
		$content = Project::update($arr);
		var_dump($content);
	}

	public function add()
	{
		$arr=$_POST;
		$c['pt']=$arr['pt'];
		$content = Project::find($c);
		$c=$content[0]->code;
		$c+=1;
		$c=substr($c, 2);
		if(empty($c)) $c="01";
		$arr['code']= date("m").$c;
//		exit;
		$add = Project::add($arr);
		if ($add)
		{
			echo 'success';
		}
	}

	public function del()
	{
		$arr=$_POST;
		$content = Project::del($arr);
		var_dump($content);
	}
	
	public function uploading()
	{
		$arr['pid'] = $_POST['id'];
		$content = Project::find($arr);
		$arr['val']=$content['0']->loading;
		if("6"==$arr['val'])
			return false;
		//判断权限
		//end
		$arr['fd'] = "loading";
		$arr['val']+=1;
		$content = Project::update($arr);
		var_dump($content);	
	}
	
	public function downloading()
	{
		$arr['pid'] = $_POST['id'];
		$content = Project::find($arr);
		$arr['val']=$content['0']->loading;
		if("0"==$arr['val'])
			return false;
		//判断权限
		//end
		$arr['fd'] = "loading";
		if($arr['val']=="1")
		{
			$arr['val']=0;
		}else
		{
			$arr['val']-=1;
		}
		$content = Project::update($arr);
		var_dump($content);	
	}
	
	public function addcode()
	{
		$arr['pid']=$_POST['pid'];
		$arr['type']=$_POST['type'];
//		var_dump($arr);
		$content = Code::find($arr);
		if(!$content)
		{
			$arr['codetext']=$_POST['codetext'];
			$contentadd = Code::add($arr);
		}
	}
	
	public function viewcode()
	{
		$arr['pid']=$_GET['id'];
		$arr['type']=$_GET['type'];
		$content = Code::find($arr);
		view('pro_code', array('title' => '工作计划', 'content' => $content,));		
	}
	
	public function editcode()
	{
		$arr=$_POST;
		$content = Code::update($arr);
		var_dump($content);
	}
}
?>